package com.zn.service.impl;

import com.zn.entity.PayTimeLimit;
import com.zn.entity.PayType;
import com.zn.mapper.PayTimeLimitMapper;
import com.zn.mapper.PayTypeMapper;
import com.zn.service.PayTimeLimitService;
import com.zn.service.PayTypeService;
import com.zn.util.DateUtils;
import com.zn.vo.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by yinjiawei on 2018/8/1.
 */
@Service
public class PayTimeLimitServiceImpl implements PayTimeLimitService {
    @Autowired
    private PayTimeLimitMapper payTimeLimitMapper;

    /**
     * 存在 true 不存在 false
     * @param payType
     * @return
     * @throws Exception
     */
    @Override
    public boolean checkLimitTime(Integer payType) throws Exception{
        boolean flag=true;
        PayTimeLimit payTimeLimit=payTimeLimitMapper.selectByPayType(payType);
        /**如果为null则不限制**/
        if(payTimeLimit!=null){
            Date nowDate= DateUtils.convertStringToDate("HH:mm", DateUtils.getTimeNow(new Date()));
            Date beginTime=DateUtils.convertStringToDate("HH:mm", DateUtils.getTimeNow(payTimeLimit.getBeginTime()));
            Date endTime=DateUtils.convertStringToDate("HH:mm", DateUtils.getTimeNow(payTimeLimit.getEndTime()));
            flag=DateUtils.belongCalendar(nowDate, beginTime, endTime);
        }
        return flag;
    }
}
